<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <el-image style="width: 313px; height: 50px" :src="require('../../assets/img/html/logo.png')" fit="contain"/>
      <h3>广软学生项目申报系统</h3>
      <el-button color="#5cb3cc" @click="logout" style="color: white">退出登录</el-button>
    </el-header>
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollapse"><el-icon><fold /></el-icon></div>
        <!-- 侧边栏菜单区域 rgb(26, 148, 188)-->
        <el-menu active-text-color="rgb(251, 185, 87)"
                 background-color="#4762B0"
                 text-color="#cdcdcd"
                 unique-opened
                 :collapse="isCollapse"
                 :collapse-transition="false"
                 router
                 :default-active="activePath">
          <!-- 一级菜单 -->
          <el-sub-menu :index="item.id + ''" v-for="item in menulist" :key="item.id">
            <!-- 一级菜单的模板区域 -->
            <template #title>
              <el-icon>
                <component :is="item.icon"/>
              </el-icon>
              <!-- 文本 -->
              <span>{{ item.authName }}</span>
            </template>

            <!-- 二级菜单 -->
            <el-menu-item :index="subItem.path" v-for="subItem in item.children" :key="subItem.id"
                          @click="saveNavState(subItem.path)">
              <template #title>
<!--                <el-icon><location/></el-icon>-->
                <!-- 文本 -->
                <span>{{ subItem.itemname }}</span>
              </template>
            </el-menu-item>
          </el-sub-menu>
        </el-menu>
      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <div class="el_border">
          <!-- 路由占位符 -->
          <router-view/>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import axios from "axios";
import {Location} from "@element-plus/icons-vue";

export default {
  components: {Location},
  data() {
    return {
      // 左侧菜单数据
      menulist: [
        {
          id: 1,
          authName: '审批人员',
          icon:'menu',
          children: [{
            id: 1,
            itemname: '全部',
            path: '/all'
          }, {
            id: 2,
            itemname: '添加',
            path: '/add_exa'
          }, 
          ]
        },
        // {
        //   id: 3,
        //   authName: '项目',
        //   icon:'MessageBox',
        //   children: [{
        //     id: 1,
        //     itemname: '删除项目',
        //     path: '/advice'
        //   }
        //   ]
        // }
      ],
      // 是否折叠
      isCollapse: false,
      // 被激活的链接地址
      activePath: ''
    }
  },
  created() {
    //this.getMenuList()
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    logout() {
      axios.get('/students/logout', {}).then(res => {
        window.sessionStorage.clear()
        let r = res.data
        alert(r.msg)
        this.$router.push('/')
      }).catch(err => {
        console.log(err)
      })
    },

    // 点击按钮，切换菜单的折叠与展开
    toggleCollapse() {
      this.isCollapse = !this.isCollapse
    },
    // 保存链接的激活状态
    saveNavState(activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    }
  }
}
</script>

<style scoped>
.home-container {
  height: 100%;
}

.el-header {
  background: #4762B0;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
}

span {
  margin-left: 15px;
}

.el-aside {
  background: #4762B0;
}

.el-menu {
  border-right: none;
}

.toggle-button {
  background: #4762B0;
  font-size: 25px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}

/*内容主体区*/
/*内容主体*/
.el-main {
  background-color: #e9eef3;
}

.el_border {
  background-color: white;
  padding: 20px 10px 10px 30px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
}
</style>
